<template>
	<view class="login">
		<view class="logo">
			<image src="../static/images/logo.png" mode="widthFix"></image>
		</view>
		<view class="form">
			<view class="list">
				<input type="text" placeholder="账号" v-model="mobile">
			</view>
			<view class="list">
				<input type="password" placeholder="密码" v-model="password">
			</view>
			<u-button type="primary" @click="login">登录</u-button>
		</view>
	</view>
</template>

<script>
	import common from '../common/js/common.js'
	export default{
		data() {
			return {
				mobile: '',
				password: ''
			}
		},
		onShow() {
			if (uni.getAccountInfoSync().miniProgram.envVersion === 'develop') {
				this.mobile = '13123654123'
				this.password = '123456'
			}
		},
		methods: {
			login() {
				if (!this.mobile) return common.toast('请输入账号')
				if (!this.password) return common.toast('请输入密码')
				common.request({
					url: this.$serverUrl + '/manage/anony/app/login',
					type: 'post',
					params: {
						mobile: this.mobile,
						password: this.password
					}
				}, res => {
					uni.setStorageSync('name', res.name)
					uni.setStorageSync('headImg', res.headImg)
					uni.switchTab({
						url: '/pages/index/index'
					})
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.login {
		display: flow-root;
		.logo {
			padding: 100rpx;
			image {
				width: 150rpx;
				margin: auto;
			}
		}
		.form {
			width: 80%;
			margin: auto;
			.list {
				margin: 40rpx 0;
				background-color: #e1e1e1;
				padding: 20rpx 30rpx;
				border-radius: 20rpx;
				input {
					display: block;
					width: 100%;
				}
			}
			/deep/ .u-button {
				margin-top: 100rpx;
			}
		}
	}
</style>